package org.bear.bearutildemo.base;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.zoke.library.util.MessageHandlerList;

/**
 * @author 大熊
 *         基类
 */
public class BaseActivity extends AppCompatActivity {

    protected Handler mHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                handleMsg(msg);
            }
        };
        String className = this.getClass().getName();
        MessageHandlerList.addHandler(className, mHandler);
    }

    /**
     * 接收handle的消息
     *
     * @param msg
     */
    protected void handleMsg(Message msg) {
    }

    @Override
    protected void onDestroy() {
        String className = this.getClass().getName();
        MessageHandlerList.removeHandler(className);
        super.onDestroy();
    }
}
